

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>流程表单数据字典</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/lib/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/lib/layuiadmin/style/admin.css" media="all">
    <style>
        html,body{height: 100%;}
        .layui-fluid{height: 94%;}
        .layui-row,.layui-col-xs12,.layui-card{height: 99%;}
    </style>

</head>
<body>


<div class="layui-fluid" id="LAY-component-grid-mobile">
    <div class="layui-row layui-col-space5">
        <div class="layui-col-xs12">
            <div class="layui-card">
                <div class="layui-card-header" style="height: 35px"><span id="title"></span></div>
                <div class="layui-card-body">
                    <form class="layui-form" action="">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label" style="width: 100px">产品/工程/摘要</label>
                                <div class="layui-input-inline">
                                    <input class="layui-input" id="epId" name="epId" type="text" placeholder="请选择产品" cn-name="产品id" value="" onclick="selectProduct(this)">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label" style="width: 120px">规格型号</label>
                                <div class="layui-input-inline">
                                    <input class="layui-input" id="model" name="model" type="text" ext-type="text" cn-name="规格型号" value="" disabled="disabled">
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label" style="width: 100px">数量</label>
                                <div class="layui-input-inline">
                                    <input class="layui-input" id="esdNumber" name="esdNumber" type="number" cn-name="数量" value="" onchange="getTotal()">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label" style="width: 120px">单位</label>
                                <div class="layui-input-inline">
                                    <select id="units" name="units" type="text" cn-name="单位" value="" disabled="disabled"></select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label" style="width: 100px">净价</label>
                                <div class="layui-input-inline">
                                    <input class="layui-input money" id="untaxedUnitPrice" name="untaxedUnitPrice" type="number" cn-name="未税单价" value="" onchange="getTotal()">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label" style="width: 120px">税率</label>
                                <div class="layui-input-inline">
                                    <input class="layui-input" id="taxRate" name="taxRate" type="number" cn-name="税率" value="" onchange="getTotal()" >
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label" style="width: 100px">暂估净额</label>
                                <div class="layui-input-inline">
                                    <input class="layui-input money" id="untaxedUnitTotal" name="untaxedUnitTotal" type="text" cn-name="未税合计" value="" disabled="disabled">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label" style="width: 120px">暂估金额（含税）</label>
                                <div class="layui-input-inline">
                                    <input class="layui-input money" id="totalTaxTotal" name="totalTaxTotal" type="text" cn-name="含税合计" value="" disabled="disabled">
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label" style="width: 100px">备注</label>
                            <div class="layui-input-block">
                                <textarea  id="remark" name="remark" placeholder="请输入内容" class="layui-textarea" style="width: 555px"></textarea>
                            </div>
                        </div>
                        <div style="text-align: center" id="subDiv">
                            <a id="save" class="layui-btn layui-btn-sm st_back1" style="margin-left:450px" lay-submit lay-filter="save"> 确  定</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="/static/lib/layuiadmin/layui/layui.js"></script>
<script src="../../../common/common.js"></script>
<script src="../../../common/jquery-3.3.1.min.js"></script>
<script src="../../../common/listTree.js"></script>
<script src="../../../common/dataGrid.js"></script>
<script src="/views/commonView/erpCommon.js"></script>
<script>
    var index = parent.layer.getFrameIndex(window.name);
    var iframe = RequestURLParam.getParam("iframeId");
    var type = RequestURLParam.getParam("type");
    var form, laydate, table;
    
    $(document).ready(function () {
        layui.use(['form', 'laydate', 'table'], function () {
            form = layui.form;
            laydate = layui.laydate;
            table = layui.table;
            loadDate();

            form.on('submit(save)', function(data){
                var formData = data.field;
                var valCode = $("#epId").attr("value-code");

                var obj = {};
                obj["epId"] = valCode;
                obj["epName"] = formData["epId"];
                obj["model"] = formData["model"];
                obj["esdNumber"] = formData["esdNumber"];
                obj["units"] = formData["units"];
                obj["taxRate"] = formData["taxRate"];
                obj["untaxedUnitPrice"] = formData["untaxedUnitPrice"];
                obj["totalTaxTotal"] = formData["totalTaxTotal"];
                obj["untaxedUnitTotal"] = formData["untaxedUnitTotal"];
                obj["remark"] = formData["remark"];

                var unit = getSelect(77, formData["units"]);
                obj["unitsName"] = unit;
                node = $('#'+iframe,parent.document)[0].contentWindow.node;
                node.attr("value-json", JSON.stringify(obj).replace(/\"/g,'\''));
                parent.layer.close(index);
            });
        });
    });
    
    function loadDate() {
        loadSelect("units",77, "");
    }

    //选择产品
    function selectProduct(e) {
        node = $(e);
        window.frameElement.id="product";
        var frameId = window.frameElement && window.frameElement.id || '';
        parent.layer.open({
            type: 2
            ,title: '选择产品'
            ,area: ['800px', '700px']
            ,maxmin: false
            ,content: '/base/workFlow/workFlow/select.html?iframeId='+frameId+"&type=product"
            ,zIndex: layer.zIndex
            ,end: function () {
                var json = node.attr("value-json");
                var product = JSON.parse(json.replace(/\'/g,'\"'));

                node.val(product.proName);
                $("[name='model']").val(product.model);
                loadSelect("units",77, product.units);
            }
        });
    }

    //加载下拉框
    function loadSelect(id, val, d) {
        var sel = $("[name='"+ id +"']");
        sel.html("<option value=''></option>")
        $.ajax({
            async:false,
            type:"post",
            url:"/wf/dictionary/list",
            data:{"parentId":val},
            contentType:'application/x-www-form-urlencoded; charset=UTF-8',
            timeout: 60000,//超时时间设置为1分钟；
            success: function (data, textStatus) {
                if(data.code == "200"){
                    $.each(data.rows, function (index, value) {
                        if(value.value == d){
                            sel.append("<option value='"+ value.value +"' selected>"+ value.cnName +"</option>");
                        }else{
                            sel.append("<option value='"+ value.value +"'>"+ value.cnName +"</option>");
                        }
                    });
                }
            },
            error: function (a, b, c) {
                // 请求出错处理,依然初始化咨询节点信息
                if (b == 'timeout') {
                    layer.alert("请求超时，请再次尝试！");
                } else {
                    layer.alert(url + "请求异常");
                }
            }
        });

        form.render();
    }

    function getSelect(val, d) {
        var v = ""
        $.ajax({
            async:false,
            type:"post",
            url:"/wf/dictionary/list",
            data:{"parentId":val},
            contentType:'application/x-www-form-urlencoded; charset=UTF-8',
            timeout: 60000,//超时时间设置为1分钟；
            success: function (data, textStatus) {
                if(data.code == "200"){
                    $.each(data.rows, function (index, value) {
                        if(value.value == d){
                            v = value.cnName;
                        }
                    });
                }
            },
            error: function (a, b, c) {
                // 请求出错处理,依然初始化咨询节点信息
                if (b == 'timeout') {
                    layer.alert("请求超时，请再次尝试！");
                } else {
                    layer.alert(url + "请求异常");
                }
            }
        });

        return v;
    }

    function getTotal() {
        var esdNumber = $("#esdNumber").val();
        var untaxedUnitPrice = $("#untaxedUnitPrice").val();
        var taxRate = $("#taxRate").val();
        var untaxedUnitTotal = 0;
        var totalTaxTotal = 0;
        if(esdNumber != undefined && untaxedUnitPrice != undefined){
            untaxedUnitTotal = esdNumber*untaxedUnitPrice;
            if(taxRate != ""){
                totalTaxTotal = untaxedUnitTotal*(1+Number(taxRate));
            }else{
                totalTaxTotal = untaxedUnitTotal;
            }
        }
        untaxedUnitTotal = untaxedUnitTotal.toFixed(2);
        totalTaxTotal = totalTaxTotal.toFixed(2);
        $("#untaxedUnitTotal").val(untaxedUnitTotal);
        $("#totalTaxTotal").val(totalTaxTotal);
    }
</script>
</body>
</html>